package com.javabase.Object.ObjectMiddle.Work;

public class Work11 {
    public static void main(String[] args) {
        Person1 person1 = new Student();//向上转型:父类引用指向子类对象
        //写代码时只看编译类型(左边)
        person1.run();//输出student run
        person1.eat();//输出Person1 eat
        //看父类，无study方法
        Student student = (Student) person1;//向下转型:把指向子类对象的父类引用，转成指向子类对象的子类引用
        //向下转型后就可以调用子类的方法和属性了
        student.eat();//然后调用就遵循就近原则了


    }

}

class Person1{
    public void run(){
        System.out.println("Person1 run");
    }
    public void eat(){
        System.out.println("Person1 eat");
    }
}

class  Student extends Person1{
    @Override
    public void run(){
        System.out.println("Student run");
    }
    public void study(){
        System.out.println("Studen study。。");
    }
}
